package org.halo.trade.data.tool;

import java.io.IOException;

import org.halo.trade.data.config.Config;
import org.halo.trade.data.tool.UUAPI.UUDLL;

public class CodeRecognizer
{
	private boolean inited = false;

	private static CodeRecognizer instance = null;

	private CodeRecognizer()
	{
		
	}

	static synchronized public CodeRecognizer getInstance()
	{
		if (instance == null)
		{
			instance = new CodeRecognizer();
			try{
				//if (!instance.init())
					return null;
			}catch(Exception ex){
				ex.printStackTrace();
				return null;
			}
		}
		return instance;
	}

	private boolean init()
	{
		if (inited)
			return true;

		try {
			if (!UUAPI.checkAPI())
			{
				System.out.print("init uuyun fail!");
				return false;
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		inited = true;
		return true;
	}

	synchronized public String[] decryptValiateCode(byte[] data, int codeType)
	{
		try
		{
			
			//写文件
			//读文件
			return UUAPI.easyDecaptcha(data, codeType);
		} catch (IOException e)
		{
			e.printStackTrace();
		}
		return null;
	}

	synchronized public void reportError(int id)
	{
		if (id == 0)
			return;

		try
		{
			UUDLL.INSTANCE.uu_reportError(id);
		} catch (Exception e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
